% fourier transform of Zernike polynomials
% numerical solution
function QM = FourierZnkPlns(Z, t_miu, f_y, D)
% Z: matrix for saving j, n and m

j_max = size(Z,2);
QM = zeros(size(f_y,1),size(f_y,2),j_max-1);
[theta, f] = cart2pol(t_miu, f_y);

for k = 1:j_max-1
    % Using the indexes in matrix Z
    % piston term has been neglected
    j = Z(1,k+1);
    n = Z(2,k+1);
    m = Z(3,k+1);
    if m == 0
        Q_agl = 1;
    else
        if mod(j,2) == 0 % j is even
            Q_agl = sqrt(2)*abs(cos(m*theta));
        else % j is odd
            Q_agl = sqrt(2)*abs(sin(m*theta));
        end
    end
    Q_j = ((sqrt(n+1)*2*abs(besselj(n+1,pi*D*f)))...
        ./(pi*D*f)).*Q_agl;
    QM(:,:,k) = Q_j;
end

    
% end of function
end
